<?php




try {
   
    $dbhost = 'localhost:3306';  // mysql服务器主机地址
		$dbuser = 'root';            // mysql用户名
		$dbpass = '';          // mysql用户名密码
		$conn = mysqli_connect($dbhost, $dbuser, $dbpass);
		
     //echo "Connected successfully"; 
    }
catch(exception $e)
    {
    echo "Connection failed: " . $e->getMessage();
    }
if(!$conn )
		{
			die('Could not connect: ' . mysqli_error());
		}
		echo 'id';
		// 设置编码，防止中文乱码
		mysqli_query($conn , "set names utf8");
		 
		

		 
		 
		mysqli_select_db( $conn, 'sockslider1' );   

if(isset($_POST["Export"])){
	  $xx=	date("Y-m-d"); 
      header('Content-Type: text/csv; charset=utf-8');  
      header('Content-Disposition: attachment; filename='.$xx.'.csv');  
      $output = fopen("php://output", "w");  
      fputcsv($output, array('ID', 'First Name', 'Last Name', 'Email', 'Joining Date'));  
      $query = "SELECT * from employeeinfo ORDER BY emp_id DESC";  
      $result = mysqli_query($conn, $query);  
	  
      while($row = mysqli_fetch_assoc($result))  
      {  
  // print_r($row);die;
           fputcsv($output, $row);  
      }  
      fclose($output);  
 }  
		?>